package com.example.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author YAO
 * @create 2021-05-13 15:50
 */
@WebServlet(name = "LoginServlet", value = "/loginServlet")
public class LoginServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=UTF-8");
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        if("admin".equalsIgnoreCase(username) && "123456".equalsIgnoreCase(password)){
            req.getSession().setAttribute("user",username);
            resp.getWriter().write("登录成功！！！");
        }else {
            req.getRequestDispatcher("/login.jsp").forward(req,resp);
        }
    }
}
